//
//  YIem_Explore_ViewController.m
//  B段_开眼
//
//  Created by YIem on 16/4/29.
//  Copyright © 2016年 Howie. All rights reserved.
//

#import "YIem_Explore_ViewController.h"

@interface YIem_Explore_ViewController ()
@property (nonatomic, strong) YIem_Explore_Detail_View *detailView;
@property (nonatomic, assign) NSInteger index;
@property (nonatomic, strong) NSMutableArray *dataArr;
@end

@implementation YIem_Explore_ViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.dataArr removeAllObjects];
    [self dataBase];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.dataArr = [NSMutableArray array];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"精彩探索";
    // 返回
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_back_normal"] style:UIBarButtonItemStylePlain target:self action:@selector(leftAction)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor colorWithRed:0.2077 green:0.2077 blue:0.2077 alpha:1.0];
    
    
    
    
    
    
    
//    self.dataArr = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", nil];
    
    
 
}
- (void)setupDraggableView
{
    self.detailView = [[YIem_Explore_Detail_View alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 11, 120, self.view.frame.size.width - ((self.view.frame.size.width / 11) * 2) , self.view.frame.size.height - 240)];
 
    
    // 这里还有  // 赋值
//    information.text = [cardsArray objectAtIndex:index];
     __block YIem_Explore_ViewController *vc = self;
    [self.detailView setMyBlock:^(UIColor *myColor) {
        vc.view.backgroundColor = myColor;
    }];
    

    
    
    self.detailView.model = [self.dataArr objectAtIndex:self.index];
    
    [self.view addSubview:self.detailView];
    self.index--;
}

- (void)dataBase
{
    NSString *url =@"http://baobab.wandoujia.com/api/v3/recommend?_s=6f99a7162454eb0beb012966f48a38c8&f=iphone&net=wifi&u=306bb8a73a2987d985b07e523582e7de25c8a6b0&v=2.0.0&vc=522";
    
    [YIem_Explore_ViewModel getDataWithPage:url andUpdate:YES andBlock:^(NSMutableArray *arr, NSString *tiemStr) {
      
        
        self.dataArr = arr;
        
        self.index = arr.count - 1;
        
        // 当所有的都完了  提示已经没有了
        
//        UILabel *noMoreCards = [[UILabel alloc] initWithFrame:CGRectMake(120, 200, 100, 100)];
//        noMoreCards.text = @"没有了";
//        [self.view addSubview:noMoreCards];
        UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 11, 120, self.view.frame.size.width - ((self.view.frame.size.width / 11) * 2) , self.view.frame.size.height - 240)];
        imgV.image = [UIImage imageNamed:@"tan_01"];
        imgV.userInteractionEnabled = YES;
        [self.view addSubview:imgV];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
        [imgV addGestureRecognizer:tap];
        
        
        UILabel *la = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, imgV.frame.size.width, 30)];
        la.textAlignment = NSTextAlignmentCenter;
        la.font = [UIFont systemFontOfSize:14];
        la.textColor = [UIColor whiteColor];
        long long int date1 = (long long int)[tiemStr intValue];
        
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:date1];
        NSDateFormatter *dateForm = [[NSDateFormatter alloc] init];
        [dateForm setDateFormat:@"MM 小时 dd 分 "];
        
        NSString *dateS = [dateForm stringFromDate:date];

        la.text =[NSString stringWithFormat:@"距离下次精彩视频还有%@", dateS]
        ;
        [imgV addSubview:la];
        UILabel *kan = [[UILabel alloc] init];
        kan.numberOfLines = 0;
        kan.textColor = [UIColor whiteColor];
        kan.text = @"- 今天推荐的视频你已经看完了 -  \n  好视频需要细细品味 \n 再看一遍发现错过的美好 \n  点击重新观看";
        kan.font = [UIFont systemFontOfSize:18 weight:20];
        [imgV addSubview:kan];
        [kan mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(imgV);
            make.size.mas_equalTo(CGSizeMake(imgV.frame.size.width, 100));
        }];


        while (self.index >= 0) {
//
//
            [self setupDraggableView];
        }
     
//        NSLog(@"%@", arr);
    }];
}
- (void)tapAction
{
    
    [self dataBase];
    
}
- (void)leftAction
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
